<template>
  <div class="container" v-loading="isLoading">
    <el-card>
      <template #header>
        <el-form inline :model="searchForm" ref="searchForm">
          <el-form-item label="标题">
            <el-input v-model="searchForm.user" placeholder="请输入标题"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitSearch">查询</el-button>
          </el-form-item>
        </el-form>
        <div class="table_tool">
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="showAddOrEdit = true"
            >新增</el-button
          >
        </div>
      </template>
      <el-table :data="tableData" border>
        <el-table-column prop="title" label="标题" />
          <el-table-column prop="thumbnail" label="缩略图">
          <template slot-scope="{ row }">
            <el-image
              style="width: 100px; height: 100px"
              :src="row.thumbnail"
              :preview-src-list="[row.thumbnail]"
            />
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120px" align="center">
          <template slot-scope="{ row }">
            <el-button type="text" @click="openEditRow(row, 'builingForm')"
              >编辑</el-button
            >
            <el-button type="text" @click="delRowById(row,row.title)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <footer class="footer">
      <el-pagination
        background
        layout="total, sizes, pager, jumper"
        :current-page="pagination.page"
        :page-sizes="[10, 20, 30, 50, 100]"
        :page-size="pagination.page_size"
        :total="tableTotal"
        @size-change="(val) => (pagination.page_size = val)"
        @current-change="(val) => (pagination.page = val)"
      />
    </footer>

    <el-dialog
      :title="builingForm.$id ? '编辑' : '新增'"
      :visible.sync="showAddOrEdit"
      width="1000px"
      @closed="() => $refs['builingForm'].resetFields()"
    >
      <el-form
        :model="builingForm"
        :rules="builingRules"
        ref="builingForm"
        label-width="5em"
      >
        <el-form-item prop="$id" hidden/>
        <el-form-item label="标题" prop="title">
          <el-input
            v-model="builingForm.title"
            placeholder="请输入标题"
          ></el-input>
        </el-form-item>
        <el-form-item prop="$image_uri" hidden/>
        <el-form-item label="图片" prop="face_img">
          <Upload
            v-model="builingForm.$image_uri"
            :file.sync="builingForm.thumbnail"
          />
        </el-form-item>
        <tinymce v-model="builingForm.content" height="300"/>
      </el-form>
      <template #footer>
        <el-button
          type="primary"
          @click="submitRowData('builingForm')"
          :loading="loading.update"
          >确 定</el-button
        >
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { table, addOrEdit } from "@/utils/mixins";
import Upload from '@/components/Upload/SingleImage.vue';
import Tinymce from '@/components/Tinymce';
export default {
  mixins: [table, addOrEdit],
  components: {
    Tinymce, Upload
  },
  data: () => ({
    searchForm: {
      $action: ["getSheRecommendList", "delSheRecommend"],
    },
    builingForm: {
      $action: ["addSheRecommend", "editSheRecommend"],
      $image_uri: "",
      title: "",
      content: ''
    },
    builingRules: {},
  }),
  methods: {
     initImg({ source, row }) {
      source.$image_uri = row.thumbnail;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
